home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / lisp / stk-3.002 / stk-3 / STk-3.1 / Tk / xlib / xgc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-01-31  |  5.0 KB  |  231 lines

  1. /* 
  2.  * xgc.c --
  3.  *
  4.  *    This file contains generic routines for manipulating X graphics
  5.  *    contexts. 
  6.  *
  7.  * Copyright (c) 1995 Sun Microsystems, Inc.
  8.  *
  9.  * See the file "license.terms" for information on usage and redistribution
  10.  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  11.  */
  12.  
  13. static char sccsid[] = "@(#) xgc.c 1.3 95/08/24 09:43:29";
  14.  
  15. #include <tk.h>
  16.  
  17. #ifdef MAC_TCL
  18. #    include <Xlib.h>
  19. #else
  20. #    include <X11/Xlib.h>
  21. #endif
  22.  
  23.  
  24. /*
  25.  *----------------------------------------------------------------------
  26.  *
  27.  * XCreateGC --
  28.  *
  29.  *    Allocate a new GC, and initialize the specified fields.
  30.  *
  31.  * Results:
  32.  *    Returns a newly allocated GC. 
  33.  *
  34.  * Side effects:
  35.  *    None.
  36.  *
  37.  *----------------------------------------------------------------------
  38.  */
  39.  
  40. GC
  41. XCreateGC(display, d, mask, values)
  42.     Display* display;
  43.     Drawable d;
  44.     unsigned long mask;
  45.     XGCValues* values;
  46. {
  47.     GC gp;
  48.  
  49.     gp = (XGCValues *)ckalloc(sizeof(XGCValues));
  50.     if (!gp) {
  51.     return None;
  52.     }
  53.  
  54.     gp->function =     (mask & GCFunction)     ?values->function    :GXcopy;
  55.     gp->plane_mask =     (mask & GCPlaneMask)     ?values->plane_mask     :~0;
  56.     gp->foreground =     (mask & GCForeground)     ?values->foreground     :0;
  57.     gp->background =     (mask & GCBackground)     ?values->background     :0xffffff;
  58.     gp->line_width =     (mask & GCLineWidth)    ?values->line_width    :0;    
  59.     gp->line_style =     (mask & GCLineStyle)    ?values->line_style    :LineSolid;
  60.     gp->cap_style =      (mask & GCCapStyle)    ?values->cap_style    :0;
  61.     gp->join_style =     (mask & GCJoinStyle)    ?values->join_style    :0;
  62.     gp->fill_style =      (mask & GCFillStyle)    ?values->fill_style    :FillSolid;
  63.     gp->fill_rule =      (mask & GCFillRule)    ?values->fill_rule    :WindingRule;
  64.     gp->arc_mode =     (mask & GCArcMode)    ?values->arc_mode    :ArcPieSlice;
  65.     gp->tile =         (mask & GCTile)        ?values->tile        :None;
  66.     gp->stipple =     (mask & GCStipple)    ?values->stipple    :None;
  67.     gp->ts_x_origin =     (mask & GCTileStipXOrigin)    ?values->ts_x_origin:0;
  68.     gp->ts_y_origin =     (mask & GCTileStipYOrigin)    ?values->ts_y_origin:0;
  69.     gp->font =         (mask & GCFont)        ?values->font        :None;
  70.     gp->subwindow_mode = (mask & GCSubwindowMode)?values->subwindow_mode:ClipByChildren;
  71.     gp->graphics_exposures = (mask & GCGraphicsExposures)?values->graphics_exposures:True;
  72.     gp->clip_x_origin = (mask & GCClipXOrigin)    ?values->clip_x_origin    :0;
  73.     gp->clip_y_origin = (mask & GCClipYOrigin)    ?values->clip_y_origin    :0;
  74.     gp->clip_mask =     (mask & GCClipMask)    ?values->clip_mask    :None;
  75.     gp->dash_offset =     (mask & GCDashOffset)    ?values->dash_offset    :0;
  76.     gp->dashes =     (mask & GCDashList)    ?values->dashes        :4;
  77.  
  78.     return gp;
  79. }
  80.  
  81. /*
  82.  *----------------------------------------------------------------------
  83.  *
  84.  * XFreeGC --
  85.  *
  86.  *    Deallocates the specified graphics context.
  87.  *
  88.  * Results:
  89.  *    None.
  90.  *
  91.  * Side effects:
  92.  *    None.
  93.  *
  94.  *----------------------------------------------------------------------
  95.  */
  96.  
  97. void
  98. XFreeGC(d, gc)
  99.     Display * d;
  100.     GC gc;
  101. {
  102.     if (gc != None) {
  103.     ckfree((char *) gc);
  104.     }
  105. }
  106.  
  107. /*
  108.  *----------------------------------------------------------------------
  109.  *
  110.  * XSetForeground, etc. --
  111.  *
  112.  *    The following functions are simply accessor functions for
  113.  *    the GC slots.
  114.  *
  115.  * Results:
  116.  *    None.
  117.  *
  118.  * Side effects:
  119.  *    Each function sets some slot in the GC.
  120.  *
  121.  *----------------------------------------------------------------------
  122.  */
  123.  
  124. void 
  125. XSetForeground(display, gc, foreground)
  126.     Display *display;
  127.     GC gc;
  128.     unsigned long foreground;
  129. {
  130.     gc->foreground = foreground;
  131. }
  132.  
  133. void 
  134. XSetBackground(display, gc, background)
  135.     Display *display;
  136.     GC gc;
  137.     unsigned long background;
  138. {
  139.     gc->background = background;
  140. }
  141.  
  142. void
  143. XSetFunction(display, gc, function)
  144.     Display *display;
  145.     GC gc;
  146.     int function;
  147. {
  148.     gc->function = function;
  149. }
  150.  
  151. void
  152. XSetFillRule(display, gc, fill_rule)
  153.     Display *display;
  154.     GC gc;
  155.     int fill_rule;
  156. {
  157.     gc->fill_rule = fill_rule;
  158. }
  159.  
  160. void
  161. XSetFillStyle(display, gc, fill_style)
  162.     Display *display;
  163.     GC gc;
  164.     int fill_style;
  165. {
  166.     gc->fill_style = fill_style;
  167. }
  168.  
  169. void
  170. XSetTSOrigin(display, gc, x, y)
  171.     Display *display;
  172.     GC gc;
  173.     int x, y;
  174. {
  175.     gc->ts_x_origin = x;
  176.     gc->ts_y_origin = y;
  177. }
  178.  
  179. void
  180. XSetArcMode(display, gc, arc_mode)
  181.     Display *display;
  182.     GC gc;
  183.     int arc_mode;
  184. {
  185.     gc->arc_mode = arc_mode;
  186. }
  187.  
  188. void
  189. XSetStipple(display, gc, stipple)
  190.     Display *display;
  191.     GC gc;
  192.     Pixmap stipple;
  193. {
  194.     gc->stipple = stipple;
  195. }
  196.  
  197. void
  198. XSetLineAttributes(display, gc, line_width, line_style, cap_style,
  199.     join_style)
  200.     Display *display;
  201.     GC gc;
  202.     unsigned int line_width;
  203.     int line_style;
  204.     int cap_style;
  205.     int join_style;
  206. {
  207.     gc->line_style = line_style;
  208.     gc->cap_style = cap_style;
  209.     gc->join_style = join_style;
  210. }
  211.  
  212. void
  213. XSetClipMask(display, gc, pixmap)
  214.     Display* display;
  215.     GC gc;
  216.     Pixmap pixmap;
  217. {
  218.     gc->clip_mask = pixmap;
  219. }
  220.  
  221. void
  222. XSetClipOrigin(display, gc, clip_x_origin, clip_y_origin)
  223.     Display* display;
  224.     GC gc;
  225.     int clip_x_origin;
  226.     int clip_y_origin;
  227. {
  228.     gc->clip_x_origin = clip_x_origin;
  229.     gc->clip_y_origin = clip_y_origin;
  230. }
  231.